package com.os.controller;


import cn.hutool.core.util.ObjectUtil;
import com.os.exception.Asserts;
import com.os.ops.Obj;
import com.os.ops.TempObj;
import com.os.result.Resp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.FileInputStream;
import java.io.IOException;


/**
 * @author 风亦未止
 * @date 2023/5/2 0:12
 */
@RestController
@RequestMapping("/dataServer/temp")
public class ObjTempController {
    @Autowired
    private TempObj tempObj;

    /**
     * 生成临时文件，返回uuid
     * @param size
     * @param hash
     * @return
     */
    @PostMapping("/{hash}")
    public String post(@RequestHeader int size , @PathVariable("hash") String hash) throws IOException {
        return tempObj.postTemp(hash,size);
    }

    /**
     * 传输对象数据流。
     */
    @PatchMapping("/{uuid}")
    public void patch(HttpServletRequest httpServletRequest, @PathVariable("uuid") String uuid) throws IOException {
        tempObj.patch(httpServletRequest.getInputStream(), uuid);
    }


    /**
     * 转正临时对象
     */
    @PutMapping("/{uuid}")
    public void put( @PathVariable("uuid") String uuid) throws IOException {
        tempObj.put(uuid);
    }

    /**
     * 删除对象
     */
    @DeleteMapping("/{uuid}")
    public void delete( @PathVariable("uuid") String uuid){
        tempObj.delete(uuid);
    }

}
